package com.cc8w.test;


import com.cc8w.admins.service.ProductClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.reactive.result.method.RequestMappingInfo;
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping;

import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.Map;

@Controller
@RequestMapping("/test")
public class testApp {

    //请求映射处理映射器
    //Spring MVC 在启动的时候将所有贴有@RequestMapping注解的请求，收集起来，封装到该对象中
    @Autowired
    private RequestMappingHandlerMapping rmhm;

    @RequestMapping("/testann")
    public String testAnn(){

        /**
         * Spring获取注解的内容:
         * 1.先要获取控制器方法(可以通过请求映射处理映射器获取方法上的@RequestMapping)
         * 2.遍历方法，可以获取其注解值
         */

        //1.获取controller中所有带有@RequestMapping标签的方法
        Map<RequestMappingInfo, HandlerMethod> handlerMethods = rmhm.getHandlerMethods();
        Collection<HandlerMethod> methods = handlerMethods.values();//获得所有方法
        for (HandlerMethod method:methods){
            System.out.println(method);
            //2.遍历所有方法，获得方法上的指定备注值
            RequestMapping annotation = method.getMethodAnnotation(RequestMapping.class);
            if(annotation != null){
                String[] value = annotation.value();
                System.out.println(value);

            }
        }


        return null;
    }

}
